package com.mes.basicdata.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mes.basicdata.dao.iface.IOperationDao;
import com.mes.basicdata.dao.iface.IOperationPartDao;
import com.mes.basicdata.domain.Operation;
import com.mes.basicdata.domain.OperationPart;
import com.mes.common.dao.BasicDao;

@Repository
public class OperationPartDao extends BasicDao<OperationPart> implements IOperationPartDao{	
	@Autowired
	private IOperationDao operationDao;

	public List<OperationPart> getOperationPartListByOperationUid(String operationUid) throws Exception {
		Operation operation = operationDao.getById(operationUid);
		Set<OperationPart> operationParts = operation.getOperationParts();
		List<OperationPart> list = new ArrayList<OperationPart>();
		
		for (OperationPart op : operationParts) {
			list.add(op);
		}
		return list;
	}

	@Override
	@SuppressWarnings("all")
	public Integer getPartCount() {
		String hql = "select count(*) from b_bill_of_materials b where b.opuid=UNIQUEID";
		Query query = this.getSessionFactory().getCurrentSession().createSQLQuery(hql);
		Object result = query.uniqueResult();
		Integer i = Integer.parseInt(String.valueOf(result));
		return i;
	}
	
}
